package Java.view.game.zhajinhua;

import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;

public class Poker extends StackPane implements Comparable<Poker> {

    private zhajinhuaFX gameFX;
    private String name;
    private ImageView imageView;
    Suit suit;//花色
    Score score;//点数

    public Poker(zhajinhuaFX gameFX, Suit suit, Score score) {
        this.gameFX = gameFX;
        this.suit=suit;
        this.score=score;
        this.name= suit.getSuitStr()+"-"+score.getScoreStr();

        imageView = new ImageView();
        setImage(false);//初始都是背面

        this.getChildren().add(imageView);

        this.setPrefSize(71, 96);
        this.setVisible(true);
    }

    public void setImage(boolean isOpen) {
        this.setVisible(true);
        if (isOpen) {
            imageView.setImage(new Image("file:src/image/poker/" + name + ".png"));
            System.out.println("file:src/image/poker/" + name + ".png");
        } else {
            imageView.setImage(new Image("file:src/image/poker/rearZhajinhua.png"));
        }
    }

    // Getters and Setters
    public zhajinhuaFX getGameFX() {
        return gameFX;
    }

    public void setGameFX(zhajinhuaFX gameFX) {
        this.gameFX = gameFX;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }



    public ImageView getImageView() {
        return imageView;
    }

    public void setImageView(ImageView imageView) {
        this.imageView = imageView;
    }

    @Override
    public String toString() {
        return "Poker{" +
                "gameFX=" + gameFX +
                ", name='" + name + '\'' +
                '}';
    }



    public Suit getSuit() {
        return suit;
    }

    public void setSuit(Suit suit) {
        this.suit = suit;
    }

    public Score getScore() {
        return score;
    }

    public void setScore( Score score) {
        this.score = score;
    }


    public int compareTo(Poker o) {
        return -(score.getScoreNum() - o.getScore().getScoreNum());
    }

    public enum Suit {
        SPADE(1), CLUB(2), HEART(3), DIAMOND(4);

        //String desc;
        public int num;

        Suit(int num) {
            this.num = num;
        }

        public int getSuitNum() {
            return num;
        }

        public String getSuitStr(){
            return String.valueOf(num);
        }

    }


    public enum Score {
        _2(2), _3(3), _4(4), _5(5), _6(6), _7(7), _8(8), _9(9), _10(10),
        J(11), Q(12), K(13), A(14);


        Score(int num) {
            this.num = num;
        }

        public int num;

        public int getScoreNum() {
            return num;
        }

        public String getScoreStr(){
            if(num==14){
                return "1";
            }else{
                return String.valueOf(num);
            }
        }
    }
}